package com.bw1806.sellergoods.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.bw1806.mapper.TbSeckillOrderMapper;
import com.bw1806.pojo.TbSeckillOrder;
import com.bw1806.pojo.TbSeckillOrderExample;
import com.bw1806.sellergoods.service.TbSeckillOrderService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import entity.PageResult;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @描述
 * @创建人 wangyue
 * @创建时间2020/11/1115:02
 */
@Service(timeout = 5000,retries = 0)
public class TbSeckillOrderServiceImpl implements TbSeckillOrderService {

    @Autowired
    private TbSeckillOrderMapper tbSeckillOrderMapper;

    @Override
    public List<TbSeckillOrder> findAll() {
        return tbSeckillOrderMapper.selectByExample(null);
    }

    @Override
    public PageResult<TbSeckillOrder> pagelist(TbSeckillOrder tbSeckillOrder,int pageNum,int pageSize) {

        PageHelper.startPage(pageNum, pageSize);

        TbSeckillOrderExample example=new TbSeckillOrderExample();

        TbSeckillOrderExample.Criteria criteria = example.createCriteria();

        if(tbSeckillOrder!=null){
            //if(tbSeckillOrder.getName()!=null && tbSeckillOrder.getName().length()>0){
            //    criteria.andNameLike("%"+tbSeckillOrder.getName()+"%");
           // }
        }

        Page<TbSeckillOrder> page= (Page<TbSeckillOrder>) tbSeckillOrderMapper.selectByExample(example);

        return new PageResult(page.getTotal(), page.getResult());
    }

    @Override
    public void save(TbSeckillOrder tbSeckillOrder) {
        Long id = tbSeckillOrder.getId();
        if(id != null && id !=0){
            tbSeckillOrderMapper.updateByPrimaryKey(tbSeckillOrder);
        } else{
            tbSeckillOrderMapper.insert(tbSeckillOrder);
        }
    }

    @Override
    public TbSeckillOrder getById(Long id) {
        return tbSeckillOrderMapper.selectByPrimaryKey(id);
    }

    @Override
    public void deletebth(Long[] ids) {
       for(long id : ids){
            tbSeckillOrderMapper.deleteByPrimaryKey(id);
        }
        //tbSeckillOrderMapper.deletebth(ids);
    }
}
